<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <el-form ref="queryForm" :model="queryForm" size="small" label-width="100px">
        <!-- 搜索 -->
        <el-form-item label="出货日期" style="display: inline-block;">
          <date-range-picker v-model="queryForm.godownEntryDate" class="date-item" />
        </el-form-item>
        <span>
          <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="doQuery()">搜索</el-button>
          <el-button v-if="crud.optShow.reset" class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="resetQuery()">重置</el-button>
          <el-button class="filter-item" size="mini" type="info" icon="el-icon-download" @click="doDownload()">导出</el-button>
        </span>
      </el-form>
      <!--表单组件-->
      <!-- <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="600px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="B2B号">
            <el-input v-model="form.b2b" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="序号">
            <el-input v-model="form.index" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="型号">
            <el-input v-model="form.model" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="采购数量">
            <el-input v-model="form.quantity" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库数量">
            <el-input v-model="form.godownQuantity" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="在途数量">
            <el-input v-model="form.onPassageQuantity" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="期望交付日">
            <el-date-picker v-model="form.expectedDeliveryDate" :disabled="true" type="date" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="客户">
            <el-input v-model="form.customer" :disabled="true" style="width: 370px;"  />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog> -->
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="queryData" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="index" width="50"/>
        <el-table-column prop="supplierName" label="供应商" />
        <el-table-column prop="taxAmount" label="含税金额（合计）" />
      </el-table>
    </div>
  </div>
</template>

<script>
import crudGodownEntryDetail from '@/api/godownEntryDetail'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'
import { downloadFile } from '@/utils/index'

const defaultForm = { id: null, b2b: null, index: null, model: null, quantity: null, expectedDeliveryDate: null, remark: null, customer: null, createBy: null, updateBy: null, createTime: null, updateTime: null, godownEntryDate: [] }
export default {
  name: 'PurchaseData',
  components: { pagination, crudOperation, rrOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '采购数据', url: 'api/purchaseData', idField: 'id', sort: 'id,desc', crudMethod: { ...crudGodownEntryDetail }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'purchaseData:add'],
        edit: ['admin', 'purchaseData:edit'],
        del: ['admin', 'purchaseData:del']
      },
      rules: {
      },
      queryForm: {
        godownEntryDate: []
      },
      queryData: []
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false,
      download: true,
      reset: true
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return false
    },
    doQuery() {
      // console.log(this.queryForm)
      crudGodownEntryDetail.getSupplierSettlmentData(this.queryForm).then(res => {
        this.queryData = res
        // this.crud.toQuery()
        // this.crud.notify('审核成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
      }).catch(err => {
        // console.log(err.response.data.message)
      })
    },
    resetQuery() {
      this.queryForm.godownEntryDate = []
    }, 
    doDownload() {
      crudGodownEntryDetail.download(null, this.queryForm.godownEntryDate).then(res => {
        this.crud.notify('导出成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
        downloadFile(res, '入库单明细', 'xlsx')
      }).catch(err => {
        console.log(err.response.data.message)
      })
    },
  }
}
</script>

<style scoped>

</style>
